<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

    <link href="/bootstraptable/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div style="text-align: right">
        <button class="btn btn-default" id="shencheng">生成派工单</button>
        <button class="btn btn-default" id="sousuo">搜索</button>

    </div>
</div>
<table id="ManufactureApply_table"></table>
<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>
<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<!--<script type="text/javascript" src="/js/index.js"></script>-->

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    $(function () {
        $("#ManufactureApply_table").bootstrapTable({
            // 请求方式
            method: "post",
            // 内容类型：如果请求方式是post，内容类型必须是application/x-www-form-urlencoded
            contentType: "application/x-www-form-urlencoded",
            // 请求路径
            url: '/ManufactureApply/checkTagShow1',
            // 数据行交替样式
            striped: true,
            // 是否是服务器端分页：server表示服务器端，client表示前端分页
            sidePagination: 'server',
            //初始化加载第一页
            // pageNumber: 1,
            //是否分页
            // pagination: true,
            // 单页记录数，页大小
            //pageSize: 5,
            // 分页列表
            // pageList: [5, 10, 20],
            //  刷新按钮
            // showRefresh:true,
            //   请求参数
            queryParams: function (params) {
                let obj = {
                    // params.limit获取组件中的页大小
                    // params.offset获取请求数据的起始索引
                    // pageSize: params.limit,
                    // pageNo: (params.offset / params.limit) + 1,
                }
                return obj;
            },

            columns: [{
                title: "点选",
                field: "a",
                formatter: function (value, row, index) {
                    return "<input type='checkbox' name='detailsNumber' value='"+row.id+"'>"
                }
            }, {
                title: "计划单编号",
                field: "applyId",
            }, {
                title: "产品编号",
                field: "productId",
                formatter: function (value, row, index) {
                    return `<a href="javascript:productId(${row.productId})">${value}</a>`
                }
            }, {
                title: "产品名称",
                field: "productName",
            }, {
                title: "描述",
                field: "productDescribe",
            }, {
                title: "数量",
                field: "amount",
            }, {
                title: "审核时间",
                field: "checkTime",
                formatter: function (value, row, index) {
                    return fortime(value)
                }
            }]
        })

    })

    function productId(productId) {
        $.post("/design/productIdshow2", {"productId": productId}, function (res) {
            if (res == true) {
                localStorage.setItem("changpin", productId)
                window.location = "/design/design_file_dengji3UI"
            } else {
                window.location = "/produce/deleteUI"
            }

        })
    }

    $("#shencheng").click(function () {
        let chks_checked = $("#ManufactureApply_table :checkbox[name='detailsNumber']:checked")
        if (chks_checked.length == 0) {
            alert("您没有选择生产计划明细")
            return
        }
        var allInputsHaveSameValue = true;
        var firstValue;
        // 获取所有的数据行对象
        // let data = $("#ManufactureApply_table").bootstrapTable("getData")
        let t1=[]
        let val_text1=[]
        for (let i = 0; i < chks_checked.length; i++) {

           let  t = $(chks_checked[i]).parent().siblings().eq(1).find("a").html()
          let val_text = $(chks_checked[i]).val()

            t1.push(t)
            val_text1.push(val_text)
        }

        let allStringsAreEqual = true; // 假设所有字符串都相等

        $.each(t1, function(index, value) {
            if (index === 0) {
                // 第一次迭代，记录第一个值
                comparisonValue = value;
            } else {
                // 之后的迭代，检查是否与第一个值一致
                if (value !== comparisonValue) {
                    allStringsAreEqual = false;
                    return false; // 终止循环
                }
            }
        })
        if (allStringsAreEqual) {
            $.ajax({
                url:"/ManufactureApply/arr",
                type:"post",
                data:JSON.stringify(val_text1),
                contentType:"application/json",
                success:function (data){

                    localStorage.setItem("val_text1",JSON.stringify(val_text1))
                    localStorage.setItem("data",JSON.stringify(data))
                    location.href="/produce/create_production_dispatch_work_orders1UI"
                }
            },"json")
        } else {
           alert("请选择产品编号一致的生产计划明细记录");
        }
    })


    function fortime(w) {
        let date = new Date(w);
        let y = date.getFullYear();
        let m = date.getMonth() + 1;
        let d = date.getDate();
        let h = date.getHours();
        let mm = date.getMinutes();
        let s = date.getSeconds();
        return (y + '-' + add(m) + '-' + add(d) + ' ' + add(h) + ':' + add(mm) + ':' + add(s));
    }

    function add(m) {
        return m < 10 ? '0' + m : m
    }
</script>
</body>
</html>